package com.yesin.geteway.config;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.yesin.auth.utils.RsaUtils;

import javax.annotation.PostConstruct;
import java.security.PublicKey;

@ConfigurationProperties(value = "yeshop.jwt")
public class AuthConfig {
    private String pubKeyPath; //公钥路径
    private String cookieName;
    private PublicKey publicKey; //公钥

    private static final Logger LOGGER = LoggerFactory.getLogger(AuthConfig.class);

    /**
     * @PostConstruct 在构造方法执行之后，执行该方法
     */
    @PostConstruct
    public void init(){
        try{
            // 获取公钥和私钥
            this.publicKey = RsaUtils.getPublicKey(pubKeyPath);

        }catch (Exception e){
            LOGGER.error("初始化公钥和私钥失败！", e);
            throw new RuntimeException();
        }
    }



    public String getPubKeyPath() {
        return pubKeyPath;
    }

    public void setPubKeyPath(String pubKeyPath) {
        this.pubKeyPath = pubKeyPath;
    }

    public String getCookieName() {
        return cookieName;
    }

    public void setCookieName(String cookieName) {
        this.cookieName = cookieName;
    }

    public PublicKey getPublicKey() {
        return publicKey;
    }


}
